package main

import (
	"context"
	"fmt"
	"go-learn/model/pb"
	"google.golang.org/grpc"
	"google.golang.org/grpc/metadata"
)

func main() {
	// 连接服务器
	conn, err := grpc.Dial("127.0.0.1:8000", grpc.WithInsecure())
	if err != nil {
		fmt.Printf("连接失败: %v", err)
	}
	defer conn.Close()

	client := pb.NewSearchServiceClient(conn)
	ctx := context.Background()
	// 使用metadata添加请求头信息
	ctx = metadata.AppendToOutgoingContext(ctx, "name", "client", "port", "8000")
	result, err := client.Search(ctx, &pb.SearchRequest{Id: 2})
	if err != nil {
		fmt.Printf("Search failed: %v", err)
	}
	fmt.Printf(result.String())
}
